package com.onlyphoto.onlymall.mvp.model

import com.onlyphoto.onlymall.api.Urls
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseModel
import com.onlyphoto.onlymall.base.BaseObserver
import com.onlyphoto.onlymall.bean.ShopBean
import com.onlyphoto.onlymall.bean.request.ShopCartDeleteBean
import com.onlyphoto.onlymall.bean.request.UpdateShopBean
import com.onlyphoto.onlymall.bean.response.GoodsDetailsBean
import com.onlyphoto.onlymall.utils.ConfigUtil
import com.onlyphoto.onlymall.utils.RxTransformer


class MShopImpl : BaseModel() {
    var url = ""

    fun requestShoppingCart(baseObserver: BaseObserver<ArrayList<ShopBean>>) {
        url = ConfigUtil.instance.getUrl(Urls.SHOPPING_CART)
        apiService().shoppingCart(url)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun updateShoppingCart(bean: UpdateShopBean, baseObserver: BaseObserver<BaseEntity>) {
        url = ConfigUtil.instance.getUrl(Urls.SHOPPING_CART)
        apiService().shoppingCartUpdate(url, bean)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun delete(bean: ShopCartDeleteBean, baseObserver: BaseObserver<BaseEntity>) {
        url = ConfigUtil.instance.getUrl(Urls.SHOPPING_CART)
        apiService().shoppingCartDelete(url, bean)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun requestDetails(baseObserver: BaseObserver<GoodsDetailsBean>, good_id: Int) {
        val url = ConfigUtil.instance.getUrl(Urls.GOODS)
        apiService().goodsDetials(url, good_id)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }
}
